<template>
  <!--一次接线图弹窗 -->
  <div class="interval">
    <!-- <div class="interval-top">
        <div class="back" @click="goBack"></div>
    </div>-->
    <div class="interval-body">
      <div class="interval-body-left">
        <div class="top">
          <div class="item1 duty-body-left borderStyle">
            <div class="title blueTitleStyle">间隔一次图</div>
            <div class="iframecon">
              <iframe :src="jgUrl" border="none" frameborder="0" style="width:100%;height:100%" />
            </div>
          </div>
          <div class="item1 duty-body-left borderStyle">
            <div class="title blueTitleStyle">间隔信息</div>
            <div class="jgxx-content">
              <div class="jgxx-state">
                <div>
                  <div class="circular"></div>
                  <div class="fontSize16">正常</div>
                </div>
                <div>
                  <div class="circular red"></div>
                  <div class="fontSize16">异常</div>
                </div>
              </div>
              <div class="jgxx-subject">
                <div class="subject-title flexCenter">在线监测</div>
                <div class="subject-con">
                  <div class="flexCenter">
                    <div class="flexCenter fontSize16">{{jgxxList.zxjcNormal}}</div>
                  </div>
                  <div class="flexCenter">
                    <div class="flexCenter fontSize16 reds">{{jgxxList.zxjcAbnormal}}</div>
                  </div>
                </div>
              </div>
              <div class="jgxx-subject">
                <div class="subject-title flexCenter">综自信息</div>
                <div class="subject-con">
                  <div class="flexCenter">
                    <div class="flexCenter fontSize16">{{jgxxList.zzxxNormal}}</div>
                  </div>
                  <div class="flexCenter">
                    <div class="flexCenter fontSize16 reds">{{jgxxList.zzxxAbnormal}}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="item2 duty-body-left borderStyle">
            <div class="title blueTitleStyle">设备台账</div>
            <div class="jgxx-content">
              <div class="img-box">
                <img class="flexCenter" src="../../../../../assets/img/Locks/mjs.png" alt />
              </div>
              <div class="sbtz-con">
                <div>
                  电压等级:
                  <span :title="equipmentMsg.voltage">{{equipmentMsg.voltage | ellipsis10}}</span>
                </div>
                <div>
                  投运日期:
                  <span :title="equipmentMsg.tyrq">{{equipmentMsg.tyrq | ellipsis10}}</span>
                </div>
                <div>
                  设备类型:
                  <span :title="equipmentMsg.sblx">{{equipmentMsg.sblx | ellipsis}}</span>
                </div>
                <div>
                  设备型号:
                  <span :title="equipmentMsg.xh">{{equipmentMsg.xh | ellipsis10}}</span>
                </div>
                <div>
                  生产厂家:
                  <span :title="equipmentMsg.sccj">{{equipmentMsg.sccj | ellipsis}}</span>
                </div>
                <div>
                  运行编号:
                  <span :title="equipmentMsg.yxbh">{{equipmentMsg.yxbh | ellipsis10}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="centers duty-body-left borderStyle">
          <div class="title blueTitleStyle">户外环境</div>
          <div class="jgxx-content">
            <div class="hwhj-con flexAround">
              <div class="flexCenter">
                <img src="../../../../../assets/img/WarningToSolve/warning_duty_icon1.png" alt />
                <div class="fontSize16">
                  <span>大气压:</span>
                  <span>{{getterStationHj.qy.value+getterStationHj.qy.unit}}</span>
                </div>
              </div>
              <div class="flexCenter">
                <img src="../../../../../assets/img/WarningToSolve/warning_duty_icon2.png" alt />
                <div class="fontSize16">
                  <span>风速:</span>
                  <span>{{getterStationHj.fs.value+getterStationHj.fs.unit}}</span>
                </div>
              </div>
              <div class="flexCenter">
                <img src="../../../../../assets/img/WarningToSolve/warning_duty_icon3.png" alt />
                <div class="fontSize16">
                  <span>温度:</span>
                  <span>{{getterStationHj.wd.value+getterStationHj.wd.unit}}</span>
                </div>
              </div>
              <div class="flexCenter">
                <img src="../../../../../assets/img/WarningToSolve/warning_duty_icon4.png" alt />
                <div class="fontSize16">
                  <span>湿度:</span>
                  <span>{{getterStationHj.sd.value+getterStationHj.sd.unit}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="bottom duty-body-left borderStyle">
          <TabInfo :dialogData="dialogData" :pointListByArea="pointListByArea" />
        </div>
      </div>
      <div class="interval-body-right">
        <div class="top duty-body-left borderStyle">
          <myVideo ref="video" />
        </div>
        <div class="bottom duty-body-left borderStyle">
          <control
            :dialogData="dialogData"
            @setControl="setControl"
            @setPreview="setPreview"
            @clickEventWin="clickEventWin"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import filter from "@/utils/filter";
import { Component, Prop, Vue } from "vue-property-decorator";
import control from "./control.vue";
//loadsh
import lodash from "lodash";
import TabInfo from "./TabInfo.vue";
import myVideo from "./video.vue";
import { GetSocketModule } from "@/store/modules/GetSocketData";

interface tabItem {
  index: number;
  id: string;
  name: string;
  active: Boolean;
}
@Component({
  components: {
    TabInfo,
    myVideo,
    control,
  },
  filters: {
    //超过20位显示 ...
    ellipsis: function (value) {
      if (!value) return "";
      if (value.length > 6) {
        return value.slice(0, 6) + "...";
      }
      return value;
    },
    ellipsis10: function (value) {
      if (!value) return "";
      if (value.length > 10) {
        return value.slice(0, 10) + "...";
      }
      return value;
    },
  },
})
export default class extends Vue {
  @Prop()
  dialogData;
  $refs: {
    video: myVideo;
  };
  get jgUrl() {
    let jgUrl = this.dialogData.jgurl || "";
    return jgUrl;
  }
  // 获取跟当前变电站相关的数据
  get pointListByCurSta() {
    let ddzid: any = this.$route.query.stationId;
    if (ddzid) {
      let getterAllAuxiliaryByStationId =
        GetSocketModule.getterAllAuxiliaryByStationId;
      return getterAllAuxiliaryByStationId[ddzid];
    } else {
      return GetSocketModule.getterAllAuxiliaryPointer;
    }
  }
  // 获取跟当前间隔相关的数据
  get pointListByBay() {
    let curBay = this.dialogData.jgid;
    let pointListByCurSta = this.pointListByCurSta;
    if (curBay) {
      let pointListByBay = pointListByCurSta.filter((v) => v.bayId === curBay);
      return pointListByBay;
    } else {
      return pointListByCurSta;
    }
  }
  // 获取当前间隔区域Id
  get currentAreaId() {
    let areaId = "";
    let pointListByBay = this.pointListByBay;
    let data = pointListByBay[0];
    if (data) {
      areaId = data.area;
    }
    return areaId;
  }
  // 获取当前区域相关测点
  get pointListByArea() {
    let pointListByArea = [];
    let getterAllAuxiliaryByAreaId = GetSocketModule.getterAllAuxiliaryByAreaId;
    let data = getterAllAuxiliaryByAreaId[this.currentAreaId];
    if (data) {
      pointListByArea = data;
    }
    return pointListByArea;
  }
  // 间隔信息list 在线监测03 综自信息就是主设备09
  get jgxxList() {
    let list = {
      zxjcNormal: 0, //在线监测正常
      zxjcAbnormal: 0,
      zzxxNormal: 0, //综自信息正常
      zzxxAbnormal: 0,
    };

    let pointListByBay = this.pointListByBay;

    pointListByBay.forEach((v) => {
      if (v.xtValue === "03") {
        if (v.isErr === "err") {
          list.zxjcAbnormal++;
        } else {
          list.zxjcNormal++;
        }
      }
      if (v.xtValue === "09") {
        if (v.isErr === "err") {
          list.zzxxAbnormal++;
        } else {
          list.zzxxNormal++;
        }
      }
    });
    return list;
  }
  // 获取环境信息
  get getterStationHj() {
    let pointListByArea = this.pointListByArea;
    // let pointListByArea = GetSocketModule.AllAuxiliaryPointer;
    let HjData = {
      "040207": {
        value: 0,
        unit: "",
        list: [],
      }, //气压监测
      "040201": {
        value: 0,
        unit: "",
        list: [],
      }, //风速监测
      "040203": {
        value: 0,
        unit: "",
        list: [],
      }, //微气象传感器温度监测
      "040102": {
        value: 0,
        unit: "",
        list: [],
      }, //温湿度传感器温度监测
      "040204": {
        value: 0,
        unit: "",
        list: [],
      }, //湿度监测
      "040103": {
        value: 0,
        unit: "",
        list: [],
      }, //湿度监测
    };
    pointListByArea.forEach((item) => {
      let type = String(item.type);
      let data = HjData[type] || {};
      let list = data.list;
      if (list) {
        list.push(item);
      }
    });
    for (let key in HjData) {
      let data = HjData[key] || {};
      let list = data.list;
      for (let i = 0; i < list.length; i++) {
        let item = list[i];
        if (item.value) {
          data.value = item.value;
          data.unit = item.unit;
          break;
        }
      }
    }
    let hj: any = {
      qy: {
        value: "--",
        unit: "",
      },
      fs: {
        value: "--",
        unit: "",
      },
      wd: {
        value: "--",
        unit: "",
      },
      sd: {
        value: "--",
        unit: "",
      },
    };
    hj.qy.value = HjData["040207"].value || "--";
    hj.fs.value = HjData["040201"].value || "--";
    hj.wd.value = HjData["040203"].value || HjData["040102"].value || "--";
    hj.sd.value = HjData["040204"].value || HjData["040103"].value || "--";
    hj.qy.unit = HjData["040207"].unit || "kPa";
    hj.fs.unit = HjData["040201"].unit || "m/s";
    hj.wd.unit = HjData["040203"].unit || "℃";
    hj.sd.unit = HjData["040204"].unit || "%";
    return hj;
  }
  // 设备台账的一条数据
  equipmentMsg = {};
  dlqsbbm = ""; //断路器设备编码
  getEquipmentMsg() {
    let params = {
      bayId: this.dialogData.jgid || "",
    };
    (this as any).$services
      .getEquipmentMsg({ data: params })
      .then((result: any) => {
        if (result.data && result.data.length) {
          this.equipmentMsg = result.data[0];
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
  }
  clickEventWin(item) {
    let video = this.$refs.video;
    if (video) {
      video.PreviewOCX.setWindowsLayout(item.layout);
    }
  }
  // 设置云台控制
  setControl(id) {
    let obj = {
      "01": "controlUpStart",
      "02": "controlUpStop",
      "03": "controlDownStart",
      "04": "controlDownStop",
      "05": "controlLeftStart",
      "06": "controlLeftStop",
      "07": "controlRightStart",
      "08": "controlRightStop",
      "09": "controlZoomInStart",
      "10": "controlZoomInStop",
      "11": "controlZoomOutStart",
      "12": "controlZoomOutStop",
      "13": "controlFocusNearStart",
      "14": "controlFocusNearStop",
      "15": "controlFocusFarStart",
      "16": "controlFocusFarStop",
      "17": "controlIrisOpenStart",
      "18": "controlIrisOpenStop",
      "19": "controlIrisCloseStart",
      "20": "controlIrisCloseStop",
    };
    let video = this.$refs.video;
    if (video) {
      let PreviewOCX = video.PreviewOCX;
      let callback = PreviewOCX[obj[id]];
      if (callback) {
        callback.call(PreviewOCX);
      }
    }
  }

  // 设置播放数据
  setPreview(item) {
    // console.log(arr);
    let stationId = this.$route.query.stationId;
    let videoData = {
      indexCode: item.videoCode,
      stationId: stationId,
      yzwbm: item.preset,
    };
    let data: any = {
      stationId,
      list: [videoData],
    };
    this.$refs.video.shipinData = data;
  }

  // 返回按钮
  private goBack(val: string) {
    window.history.back();
    // this.$router.push("index");
  }
  // get zxjcSl(){

  // }
  created() {}
  mounted() {
    this.getEquipmentMsg();
  }
}
</script>

<style lang="scss" scoped>
.interval {
  widows: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0 0.24rem 0.24rem 0.24rem;
  // background-color: gray;
  &-top {
    width: 100%;
    height: 3.5%;
    // background-color: pink;
    display: flex;
    align-items: center;
    .back {
      width: 0.9rem;
      height: 0.31rem;
      margin-left: auto;
      background-image: url("../../../../../assets/img/return.png");
      background-size: 100% 100%;
      background-repeat: no-repeat;
      background-position: center;
    }
  }
  .jgxx-content {
    width: 100%;
    height: calc(100% - 0.27rem);
    .img-box {
      width: 100%;
      height: 60%;
      img {
        height: 100%;
        margin: 0 auto;
      }
    }
    .sbtz-con {
      width: 100%;
      height: 40%;
      display: flex;
      flex-wrap: wrap;
      box-sizing: border-box;
      padding: 0.1rem 0.1rem 0.05rem 0.1rem;
      > div {
        width: 50%;
        height: 33%;
        font-size: 0.14rem;
        white-space: nowrap;
      }
    }
    .hwhj-con {
      width: 100%;
      height: 100%;
      > div {
        > img {
          width: 0.3rem;
          height: 0.3rem;
          margin-right: 0.1rem;
        }
      }
    }
  }
  .jgxx-state {
    width: 100%;
    height: 16%;
    display: flex;
    justify-content: center;
    align-items: center;
    > div {
      width: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      .circular {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background-color: #01fe5a;
        margin-right: 10px;
      }
      .red {
        background-color: #e1044f;
      }
    }
  }
  .jgxx-subject {
    width: 100%;
    height: 40%;
    .subject-title {
      width: 100%;
      height: 20%;
      font-size: 0.18rem;
    }
    .subject-con {
      width: 100%;
      height: 80%;
      display: flex;
      > div {
        width: 50%;
        height: 100%;
        > div {
          height: 0.7rem;
          width: 0.7rem;
          border-radius: 50%;
          border: 0.1rem solid #01fe5a;
        }
        .reds {
          border: 0.1rem solid #e1044f;
        }
      }
    }
  }

  .fontSize16 {
    font-size: 0.16rem;
  }
  .flexCenter {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .flexAround {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  &-body {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    // background-color: pink;
    &-left {
      width: 60.6%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      // background-color: pink;
      .top {
        width: 100%;
        height: 40%;
        display: flex;
        justify-content: space-between;
        // background-color: powderblue;
        .item1 {
          width: 27.7%;
          height: 100%;
          // background-color: plum;
          .iframecon {
            width: 100%;
            height: calc(100% - 0.27rem);
          }
        }
        .item2 {
          width: 40.8%;
          height: 100%;
          // background-color: plum;
        }
      }
      .centers {
        width: 100%;
        height: 10.5%;
        // background-color: gray;
      }
      .bottom {
        width: 100%;
        height: 46.4%;
        // background-color: powderblue;
      }
    }
    &-right {
      width: 38.5%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      // background-color: powderblue;
      .top {
        width: 100%;
        height: 52%;
      }
      .bottom {
        width: 100%;
        height: 46.4%;
      }
    }
  }
}
</style>
